<?php

class ToChuc extends Zend_Db_Table_Abstract{
    
    protected $_name = 'bk_tochuc';
	
    function SelectToChucByID_BM1($id_bm1){
		global $db;

		$sql = "SELECT tc.* FROM bk_tochuc tc INNER JOIN bk_mau1 m1 ON tc.ID_TC = m1.ID_TC WHERE m1.ID_BK1 = ?";

		return $db->query($sql,$id_bm1)->fetch();
	}
        function SelectToChucByID_BM2($id_bm2){
		global $db;

		$sql = "SELECT tc.* FROM bk_tochuc tc INNER JOIN bk_mau2 m1 ON tc.ID_TC = m1.ID_TC WHERE m1.ID_BK2 = ?";

		return $db->query($sql,$id_bm2)->fetch();
	}

	function SelectToChucByID_U($id_u){
		global $db;

		$sql = "SELECT tc.* FROM bk_tochuc tc WHERE tc.ID_U = ?";

		return $db->query($sql,$id_u)->fetch();
	}
        
        function SelectToChucByID($id){
		global $db;

		$sql = "SELECT tc.* FROM bk_tochuc tc 
                    inner join bk_mau1 bm1 on bm1.ID_TC= tc.ID_TC
                    WHERE bm1.ID_BK1 = ?";

		return $db->query($sql,$id)->fetch();
	}
        function SelectToChucByIDBK2($id){
		global $db;

		$sql = "SELECT tc.* FROM bk_tochuc tc 
                    inner join bk_mau2 bm1 on bm1.ID_TC= tc.ID_TC
                    WHERE bm1.ID_BK2 = ?";

		return $db->query($sql,$id)->fetch();
	}

	function UpdateByID_TC($parameter,$id_tc){
		global $db;

		$sql = "UPDATE bk_tochuc SET
			NAME = ?
			,GPDKKD_SO = ?
			,GPDKKD_NGAY = ?
			,TRUSO = ?
			,DIENTHOAI = ?
			,DAIDIEN = ?
			,FAX = ?
		WHERE ID_TC = ?";

		$db->query($sql,Array(
			$parameter["NAME"]
			,$parameter["GPDKKD_SO"]
			,$parameter["GPDKKD_NGAY"]
			,$parameter["TRUSO"]
			,$parameter["DIENTHOAI"]
			,$parameter["DAIDIEN"]
			,$parameter["FAX"]
			,$id_tc
		));

	}

}